﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using WebPortal.Models.EntityModels;
using WebPortal.Helpers;


namespace WebPortal.Models.ViewModel
{
    public class UserSecurityModel
    {
        [Required]
        [RegularExpression("[.\\-_a-z0-9]+@([a-z0-9][\\-a-z0-9]+\\.)+[a-z]{2,6}")]
        public string Email { get; set; }

        [Required]
        public string OldPassword { get; set; }

        public string NewPassword { get; set; }

        public string ConfirmPassword { get; set; }

        public UserSecurityModel() { }

        public UserSecurityModel(Users u)
        {
            Email = u.Email;
        }

        public void CopyToUser(ref Users u)
        {
            u.Email = Email;
            if (NewPassword != null && !NewPassword.Equals(""))
                u.Password = MD5.Encrypt(NewPassword);
        }
    }
}